import { defHttp } from '@/utils/http/axios'
import { AddRoomParams } from './model'
import { BasicOptions } from '../model/baseModel'

enum API {
  ROOM_LIST = '/roomManage/list',
  ROOM = '/roomManage/'
}

const DEFAULT_OPTS = {
  isTransformResponse: false
}

/** 获取房间列表 */
export function getRoomList(type?: string, status?: string) {
  return defHttp.get({
    url: API.ROOM_LIST,
    params: { type, status }
  }, DEFAULT_OPTS)
}

/** 新增房间 */
export function addRoom(data: AddRoomParams) {
  return defHttp.post({
    url: API.ROOM,
    data
  }, DEFAULT_OPTS)
}

/** 编辑房间 */
export function editRoom(data: AddRoomParams) {
  return defHttp.put({
    url: API.ROOM,
    data
  }, DEFAULT_OPTS)
}

/** 修改房间状态 */
export function editRoomStatus(id: string, status: string) {
  return defHttp.put({
    url: API.ROOM + id,
    data: { status }
  }, DEFAULT_OPTS)
}

/** 删除房间 */
export function deleteRoom(id: string) {
  return defHttp.delete({
    url: API.ROOM + id,
  }, DEFAULT_OPTS)
}

/** 获取房间列表下拉选项 */
export async function getRoomListOpts(type?: string, status?: string): Promise<BasicOptions[]> {
  const data = await defHttp.get({
    url: API.ROOM_LIST,
    params: { type, status }
  }, DEFAULT_OPTS)

  return (data || []).map(item => {
    return {
      label: item.name,
      value: item.id
    }
  })
}